package com.itic.market.mobile.welcome;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.market.mobile.base.BaseMobileInterface;
import com.itic.market.system.welcome.persistence.model.Welcome;
import com.itic.market.system.welcome.persistence.model.WelcomeExample;
import com.itic.market.system.welcome.persistence.model.WelcomeExample.Criteria;
import com.itic.market.system.welcome.service.WelcomeService;


/**
 * 用户登入接口类
 * @author 许小宝
 * 2017年07月25日  14时11分
 */
@Controller
@RequestMapping(value="/mobile/welcome")
public class MarketWelcomeInterface
     extends BaseMobileInterface {
    
	@Autowired
	private WelcomeService welcomeService;
    /**
     * APP用户注册成商家
     * @return
     */
    @RequestMapping(value="/url")
    @ResponseBody
    public Map<String,Object> index(HttpServletRequest request,HttpServletResponse response){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		String url = "http://file.jhjvip.cn/images/welcome.jpg";
    		WelcomeExample example = new WelcomeExample();
    		example.setOrderByClause("CREATE_TIME DESC");
    		Criteria criteria = example.createCriteria();
    		criteria.andIsEffectiveEqualTo(DBConst.TRUE).andTypeEqualTo("002");
    		List<Welcome> list = welcomeService.list(example);
    		if( list.size() > 0 ){
    			Welcome welcome = list.get(0);
    			url=welcome.getUrl();
    		}
    		resultMap.put(DATA, url);
    		result = SUCCESS;
    		errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	log(e);
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    
}